import 'package:hairen_app/server/server.dart';
import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import '../plug/Carousel.dart';
import 'package:flutter_plugin/flutter_plugin.dart';
class BannerPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => new BannerPageState();
}

class BannerPageState extends State<BannerPage> {

  List banners=[];
  bool isBanner=true;
  @override
  void initState() {
    super.initState();
    getBanners();
  }

  getBanners(){
    if(isBanner){
      Server.getBanner().then((res){
        setState(() {
          banners=res['data'][0]['items'];
          for(var i=0;i<banners.length;i++){
            if(int.parse(banners[i]["url"])==0){
              FlutterPlugin.clip(banners[i]["content"].toString());
            }
          }
          isBanner=false;
        });

      });
    }

  }
  @override
  void dispose() {
    super.dispose();
  }
  @override
  Widget build(BuildContext context) {
    return !isBanner?new Carousel(
      Imgs: banners,
      borderRadius: Radius.circular(10.0),
    ):new SpinKitWave(
      color: Color.fromRGBO(251, 114, 153, 1.0),
      size: 30.0,
    );
  }
}
